home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Samples / SampleCode / CustomAttribute / IsAppRunning.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-07  |  2.3 KB  |  81 lines  |  [TEXT/KAHL]

  1. #include "IsAppRunning.h"
  2.  
  3.  
  4. // check to see using the process manager whether our 
  5. // target app is running
  6.  
  7. Boolean IsAppRunning( OSType targetType,
  8.                       OSType targetSignature,
  9.                       ProcessSerialNumber *targetPSN, 
  10.                       ProcessInfoRec *targetPIRec, 
  11.                       StringPtr targetName )
  12. {
  13.     
  14.     // we want to return the PSN if there is one
  15.     // we want to return the Proc Info Rec if there is one
  16.     // we will return true if we found our App
  17.     // false if it wasn't running.
  18.     
  19.     // we need to loop through all the running processes and 
  20.     // find one that looks like our background task.
  21.     
  22.     // This is all standard stuff - see IM Process Manager, page 2-6
  23.     
  24.     targetPSN->highLongOfPSN = 0 ;
  25.     targetPSN->lowLongOfPSN = kNoProcess ;
  26.     
  27.     // set up the info record, for the call to get process info
  28.     targetPIRec->processInfoLength = sizeof( ProcessInfoRec ) ;
  29.     targetPIRec->processName = targetName ;    // the name will be put in here
  30.     targetPIRec->processAppSpec = nil ;        // we do not care about the location of the app
  31.     
  32.     // right, loop through the running processes
  33.     while( GetNextProcess( targetPSN ) == noErr ) {
  34.     
  35.         if( GetProcessInformation( targetPSN, targetPIRec ) == noErr ) {
  36.             
  37.             if( targetPIRec->processType == targetType 
  38.                 && targetPIRec->processSignature == targetSignature )
  39.                 
  40.                 return true ;
  41.         }
  42.     }
  43.     return false ;
  44. }
  45.  
  46.  
  47. // search in the desktop database for the app so that we can launch it
  48. OSErr LaunchApp( OSType targetSignature)
  49. {
  50.     DTPBRec                theDatabase ;
  51.     LaunchParamBlockRec    theLPB ;
  52.     FSSpec                targetFSSpec ;
  53.     OSErr                err ;
  54.     
  55.     theDatabase.ioCompletion = 0L ;
  56.     theDatabase.ioNamePtr = 0L ;
  57.     theDatabase.ioVRefNum = -1 ;    // restrict search to boot volume only
  58.     
  59.     if(( err = PBDTGetPath( &theDatabase )) != noErr )
  60.         return err ;
  61.         
  62.     theDatabase.ioIndex = 0 ;
  63.     theDatabase.ioFileCreator = targetSignature ;
  64.     theDatabase.ioNamePtr = (StringPtr)targetFSSpec.name  ;
  65.     
  66.     if(( err = PBDTGetAPPL( &theDatabase, false )) != noErr)
  67.         return err ;
  68.         
  69.     targetFSSpec.vRefNum     = theDatabase.ioVRefNum ;
  70.     targetFSSpec.parID         = theDatabase.ioAPPLParID ;
  71.     
  72.     theLPB.launchBlockID     = extendedBlock ;
  73.     theLPB.launchEPBLength     = extendedBlockLen ;
  74.     theLPB.launchFileFlags     = 0 ;
  75.     theLPB.launchControlFlags = launchContinue + launchNoFileFlags + launchUseMinimum ;
  76.     theLPB.launchAppSpec     = &targetFSSpec ;
  77.     theLPB.launchAppParameters = 0L ;
  78.     
  79.     return( LaunchApplication( &theLPB ) ) ;
  80. }
  81.